use serde::{Serialize, Deserialize};
use crate::extends::core::config::application::{Application, Profiles, Server};
use crate::extends::core::config::framework::{Cache, Datasource, DbPool, Docs, Framework, Logging, Redis, SwaggerUi};
use crate::extends::core::config::micro_services::Microservice;

/// 定义 app context 配置结构体
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AppContext {
    pub application: Application,
    pub framework: Framework,
    pub microservices: Option<Vec<Microservice>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TempApplicationContext {
    pub application: Application,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TempFrameworkContext {
    pub framework: Framework,
    pub microservices: Option<Vec<Microservice>>,
}

impl Default for AppContext {
    fn default() -> Self {
        AppContext {
            application: Application {
                name: "xinhou-openai-framework".to_string(),
                version: "v1.0.0".to_string(),
                author: "shenpeng".to_string(),
                email: "sp_hrz@qq.com".to_string(),
                server: Server {
                    context_path: "/".to_string(),
                    host: "0.0.0.0".to_string(),
                    port: 8080,
                    reload: Some(false),
                },
                profiles: Profiles { active: "dev".to_string() },
            },
            framework: Framework {
                datasource: Datasource {
                    url: None,
                    host: "127.0.0.1".to_string(),
                    port: 33307,
                    username: "root".to_string(),
                    password: "123456".to_string(),
                    database: "rust_db".to_string(),
                    db_pool: DbPool {
                        pool_pre_ping: false,
                        pool_size: 0,
                        pool_timeout: 0,
                        echo: false,
                    },
                },
                redis: Redis {
                    host: "127.0.0.1".to_string(),
                    port: 6379,
                    password: None,
                    timeout: Some("10000ms".to_string()),
                    database: Some(0),
                },
                cache: Cache { enable_type: "redis".to_string() },
                logging: Logging { path: "temps/logs/".to_string(), level_root: "info".to_string() },
                docs: Docs {
                    swagger_ui: SwaggerUi { enabled: true, path: "/swagger-ui.html".to_string() },
                    enabled: true,
                    packages_to_scan: "apps/**".to_string(),
                    paths_to_match: "/**".to_string(),
                },
            },
            microservices: None,
        }
    }
}










